﻿using Microsoft.AspNetCore.Mvc;
using brand.cyt369.com.MODELS;
using brand.cyt369.com.models;

namespace brand.cyt369.com.Controllers
{
    public class BrandController : Controller
    {
        public IActionResult Index(string id)
        {
            if (!string.IsNullOrEmpty(id))
            {
                var argsJson = Base64.Base64ToJSON(id);
                long? brandId = argsJson.GetInteger("id");
                if (brandId.HasValue)
                {
                    var brandDetail = brand.cyt369.com.dal.BrandService.Instance.GetBrandByID(brandId.Value);
                    var citys=brand.cyt369.com.dal.CityService.Instance.GetCitys();
                    ViewBag.brandDetail = brandDetail;
                    ViewBag.citys = citys;

                    return View();
                }
                return Ok();
            }
            else
            {
                return Ok();
            }
        
          
        }

        [HttpGet]
        public IActionResult GetBrandExtension(int brandId){
            var brandExtension = brand.cyt369.com.dal.BrandService.Instance.GetBrandExtension(brandId);
            return Json(brandExtension);
        }

        [HttpGet]
        public IActionResult GetBrandsByCategoryParentID(int categoryParentID)
        {
            var brands = brand.cyt369.com.dal.BrandService.Instance.GetBrandsByCategoryParentID(categoryParentID);
            var temp = brands.ToList();
            return Json(brands);
        }
    }
}
